<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <title>学生信息管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/admin.css">
    <script src="${pageContext.request.contextPath}/layui/layui.js"></script>
    <script src="${pageContext.request.contextPath}/layui/axios.min.js"></script>
    <script src="${pageContext.request.contextPath}/layui/common.js"></script>
</head>
<body>
<form class="layui-form layui-top-win" lay-filter="user">
    <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
    <div class="layui-form-item">
        <label class="layui-form-label">课程名</label>
        <div class="layui-input-block">
            <input type="text" name="name" placeholder="请输入课程名" lay-verify="required"
                   autocomplete="off" class="layui-input" value="${course.name}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">学分</label>
        <div class="layui-input-block">
            <input type="text" name="credit" placeholder="请输入学分" value="${course.credit}"
                   lay-verify="required|number" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">课程类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="必修" <c:if test="${course.type == 1}"> checked</c:if>>
            <input type="radio" name="type" value="0" title="选修" <c:if test="${course.type == 0}"> checked</c:if>>
        </div>
    </div>

</form>

<script>

    layui.use(['form', 'laydate'], function () {
        let form = layui.form;
        let $ = layui.jquery;

        form.on('submit', function (data) {
            axios.post("/teacher/course/modify${course.id}", {...data.field, id: '${course.id}'}).then(ret => {
                if (ret.data.status) {
                    // 刷新父组件的表格
                    parent.layui.table.reload("job")
                    parent.layer.msg("课程修改成功")
                    // 关闭父组件的弹出层
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                } else if (ret.data.code === 20000) {
                    // 获取错误消息
                    for (let key in ret.data.error) {
                        layer.msg(ret.data.error[key])
                    }
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</body>
</html>
